package com.zl.learning.arithmetic.my;

import java.util.Arrays;

/**
 * 两两比较，每次把最大或最小数据放到最后
 */
public class BubbleSort {

    //    public static int[] a = getRandomArray();
    public static int[] a = {98, 54, 53, 91, 70, 42, 25, 61, 38, 82};

    public static void bubbleSort(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = 0; j < a.length - i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int tmp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = tmp;
                }
            }
        }
    }


    public static void main(String[] args) {
        System.out.println(Arrays.toString(a));
        bubbleSort(a);
        System.out.println(Arrays.toString(a));
    }
}
